home *** CD-ROM | disk | FTP | other *** search
Text File | 1997-06-28 | 1.7 KB | 115 lines | [TEXT/CWIE] |
- // Progress.cp
-
- #ifndef Progress_h
- #include "Progress.h"
- #endif
-
- Progress::Progress()
- : portion( 0 ),
- total( maxuint32 ),
- totalKnown( false )
- {
- }
-
- Progress::Progress( uint32 theTotal )
- : portion( 0 ),
- total( theTotal ),
- totalKnown( true )
- {
- }
-
- void Progress::Clear()
- {
- bool changed = totalKnown;
-
- totalKnown = false;
- total = maxuint32;
- portion = 0;
-
- if ( changed )
- Announce();
- }
-
- void Progress::Clear( uint32 newTotal )
- {
- bool changed = !totalKnown || portion > 0;
-
- totalKnown = true;
- total = newTotal;
- portion = 0;
-
- if ( changed )
- Announce();
- }
-
- void Progress::SetTotal( uint32 newTotal )
- {
- Assert( portion <= newTotal );
-
- if ( totalKnown && total == newTotal )
- return;
-
- bool changed = !totalKnown || portion > 0;
-
- totalKnown = true;
- total = newTotal;
-
- if ( changed )
- Announce();
- }
-
- void Progress::SetPortion( uint32 newPortion )
- {
- Assert( newPortion <= total );
-
- if ( newPortion == portion )
- return;
-
- portion = newPortion;
- Announce();
- }
-
- void Progress::Set( uint32 newPortion, uint32 newTotal )
- {
- Assert( newPortion <= newTotal );
-
- if ( !totalKnown )
- {
- totalKnown = true;
- total = newTotal;
- portion = newPortion;
- Announce();
- return;
- }
-
- bool changed = true;
-
- if ( portion == 0 && newPortion == 0 )
- changed = false;
-
- if ( portion == total && newPortion == newTotal )
- changed = false;
-
- if ( portion == newPortion && total == newTotal )
- changed = false;
-
- portion = newPortion;
- total = newTotal;
-
- if ( changed )
- Announce();
- }
-
- void Progress::operator++()
- {
- Assert( !Finished() );
- portion++;
- Announce();
- }
-
- double Progress::Fraction() const
- {
- Assert( totalKnown );
- return double( portion ) / double( total );
- }
-